package com.colorful.insuranceproject.request;

import android.os.Handler;

import com.colorful.insuranceproject.bean.DrugAddressBean;
import com.colorful.insuranceproject.bean.QRCodeBean;
import com.colorful.insuranceproject.bean.TransactionRecordBean;
import com.colorful.insuranceproject.bean.VerifyBean;
import com.colorful.insuranceproject.consts.URLConst;
import com.lovely3x.common.requests.impl.HandlerRequestImpl;
import com.lovely3x.common.utils.ALog;
import com.lovely3x.common.utils.Response;
import com.lovely3x.jsonparser.model.JSONObject;

import okhttp3.OkHttpClient;

/**
 * Created by handsome-Bob on 2017/8/19.
 * <p>
 * 微药板块的请求器
 */
public class MicroDrugRequest extends BaseRequest {

    public MicroDrugRequest(Handler handler) {
        super(handler);
    }

    /**
     * 获取交易记录
     *
     * @param currentIndex 页码展示
     * @param what         handler传递值
     */
    public void getTransactionRecordUrl(final int currentIndex, int what) {
        process(new ProcessResultExtension() {
            @Override
            public void onResult(Response res, JSONObject result) throws Exception {
                if (res.isSuccessful) {
                    ALog.e(TAG, "获取交易记录---------------->" + result);
                    res.obj = result.getJSONArray(DATA_KEY).createObjects(TransactionRecordBean.class);
                }
            }

            @Override
            public void onRequestBefore(Response res, OkHttpClient client) {
                res.addtional = currentIndex;
            }
        }, URLConst.GET_TRANSACTION_RECORD_URL, what, "page", currentIndex);
    }

    /**
     * 获取药店地址的的列表
     *
     * @param latitude     精度
     * @param longitude    纬度
     * @param currentIndex 页码
     * @param what         handler
     */
    public void getDrugAddressList(double latitude, double longitude, int isChild, String areaName, final int currentIndex, int what) {
        process(new ProcessResultExtension() {
                    @Override
                    public void onResult(Response res, JSONObject result) throws Exception {
                        if (res.isSuccessful) {
                            ALog.e(TAG, "获取药店地址的的列表---------------->" + result);
                            res.obj = result.getJSONArray(DATA_KEY).createObjects(DrugAddressBean.class);
                        }
                    }

                    @Override
                    public void onRequestBefore(Response res, OkHttpClient client) {
                        res.addtional = currentIndex;
                    }
                }, URLConst.GET_DRUG_ADDRESS_URL, what, "page", currentIndex, "lat", latitude, "lng", longitude, "pageLength", 10, "isChild", isChild
                , "areaName", areaName);
    }

    /**
     * 绑定支付密码
     *
     * @param card  身份证
     * @param name  真实姓名
     * @param phone 电话号码
     * @param code  验证码
     * @param what  handler传递值
     */
    public void judgePayPwdUrl(String card, String name, String phone, String code, String id, int what) {
        process(new ProcessResult() {
            @Override
            public void onResult(Response res, JSONObject result) throws Exception {
            }
        }, URLConst.BIND_PAY_PWD_JUDGE_URL, what, "userName", name, "idCard", card, "userPhone", phone, "phoneCode", code, "messageId", id);
    }


    /**
     * 获取短信
     *
     * @param phone
     * @param what
     */
    public void getBindPayPwdUrl(String phone, int what) {
        process(new ProcessResult() {
            @Override
            public void onResult(Response res, JSONObject result) throws Exception {
                if (res.isSuccessful) {
                    res.obj = result.getJSONObject(DATA_KEY).createObject(VerifyBean.class);
                    ALog.e(TAG, "绑定支付密码---------------------->" + result);
                }
            }
        }, URLConst.BIND_PAY_PWD_URL, what, "userPhone", phone);
    }

    /**
     * 设置支付密码
     *
     * @param pwdAgain 密码
     * @param what     handler 传递值
     */
    public void setPayPwd(String pwdAgain, String id, int what) {
        process(new HandlerRequestImpl.EmptyProcessResult(), URLConst.SET_PAY_PWD_URL, what, "idCard", id, "newPassowrd", pwdAgain);
    }

    /**
     * 获取药店付款码
     *
     * @param what handler
     */
    public void getQrCode(int what) {
        process(new ProcessResult() {
            @Override
            public void onResult(Response res, JSONObject result) throws Exception {
                if (res.isSuccessful) {
                    ALog.e(TAG, "获取药店付款码--------------->" + result);
                    res.obj = result.getJSONObject(DATA_KEY).createObject(QRCodeBean.class);
                }
            }
        }, URLConst.GET_PAY_QR_CODE_URL, what);
    }

    /**
     * 设置退款金额
     *
     * @param money 需要退回的钱
     * @param what  handler传递值
     */
    public void setReturnMoney(String money, int what) {
        process(new ProcessResult() {
            @Override
            public void onResult(Response res, JSONObject result) throws Exception {
                if (res.isSuccessful) {
                    res.obj = result.getJSONObject(DATA_KEY);
                    ALog.e(TAG, "设置退款金额-------------------------->" + result);
                }
            }
        }, URLConst.SET_RETURN_MONEY_URL, what, "refundMoney", money);
    }

    /**
     * 关于二位码页面点击推送对话框后的接口操作
     *
     * @param confirm 状态
     * @param uid     uid
     * @param content 内容
     * @param what    handler 传递值
     */
    public void aboutQrPageConst(String confirm, String uid, String content, int what) {
        process(new ProcessResult() {
            @Override
            public void onResult(Response res, JSONObject result) throws Exception {
                ALog.e(TAG, "关于二位码页面点击推送对话框后的接口操作------------>" + result              );
            }
        }, URLConst.ABOUT_QR_PAGE_CONST, what, "type", confirm, "userId", uid, "msg", content);
    }
}
